/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package io.renren.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.exception.RRException;
import io.renren.common.utils.Constant;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.sys.dao.SysOrgDao;
import io.renren.modules.sys.dao.SysOrgDao;
import io.renren.modules.sys.entity.SysOrgEntity;
import io.renren.modules.sys.entity.SysOrgEntity;
import io.renren.modules.sys.service.SysOrgService;
import io.renren.modules.sys.service.SysOrgService;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 系统机构
 *
 * @author Mark sunlightcs@gmail.com
 */
@Service("sysOrgService")
public class SysOrgServiceImpl extends ServiceImpl<SysOrgDao, SysOrgEntity> implements SysOrgService {


	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		String orgName = (String)params.get("orgName");

		IPage<SysOrgEntity> page = this.page(
			new Query<SysOrgEntity>().getPage(params),
			new QueryWrapper<SysOrgEntity>()
				.like(StringUtils.isNotBlank(orgName),"org_name", orgName)
		);

		return new PageUtils(page);
	}

	@Override
	public SysOrgEntity queryByOrgName(String orgName) {
		return baseMapper.queryByOrgName(orgName);
	}

	@Override
	@Transactional
	public void saveOrg(SysOrgEntity org) {
		this.save(org);
	}

	@Override
	@Transactional
	public void update(SysOrgEntity org) {
		this.updateById(org);
	}

	@Override
	public void deleteBatch(Long[] orgId) {
		this.removeByIds(Arrays.asList(orgId));
	}

}